/**
 * @file: WeighingController
 * @author: michael
 * @date: 2019/12/23 14:58
 * @copyright: 南京凯盛
 */
package cn.com.kisen.kdc.web;

import cn.com.kisen.kdc.constant.KDCConst;
import cn.com.kisen.kdc.service.weighing.WeighingRecordService;
import cn.com.kisen.kdc.service.weighing.cmt.CMTStandardService;
import cn.com.kisen.kdc.service.weighing.smartlms.LmsService;
import com.kisen.common.core.utils.DateUtil;
import com.kisen.common.core.utils.property.PropertyUtil;
import core.common.dto.SimpleListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;
import java.util.Properties;

/**
 *  物流数据入口
 *   数据来源当前支持 1.[default] mms ;2. smartlms ; 3.CMTWeight
 *
 * @author michael
 * @version 1.0 Created on 2019/12/23 14:58
 */
@RestController
@RequestMapping({"/weighing", "/giantboard"})
public class WeighingController {

    @Autowired
    private WeighingRecordService weighingRecordService;

    @Autowired
    private CMTStandardService cmtStandardService;

    @Autowired
    private LmsService lmsService;

    /**
     * 获取进出厂车辆信息， 包括总数
     * 起止时间格式 ：yyyy-MM-dd HH:mm:ss
     *
     * @param reqMap
     * @return
     */
    @RequestMapping("/getTruckData")
    public SimpleListResult getTruckData(@RequestBody Map<String, Object> reqMap) {
        SimpleListResult simpleListResult = new SimpleListResult();
        Integer inout = (Integer) reqMap.get("inout");
        String start = reqMap.get(KDCConst.Param_Start).toString();
        String end = reqMap.get(KDCConst.Param_End).toString();
//        if (this.getGoodsSource() == 1) {
//            try {
//                simpleListResult.setData(weighingRecordService.getTruck(inout, DateUtil.parse1(start).getTime(),
//                        DateUtil.parse1(end).getTime()));
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//        } else if (this.getGoodsSource() == 2) {
            simpleListResult.setData(cmtStandardService.getTruck(inout, start, end));
//        } else {
//            simpleListResult.setData(lmsService.getTruck(inout, start, end));
//        }
        simpleListResult.setTotal(simpleListResult.getData().size());
        return simpleListResult;
    }

    /**
     * 获取物流数据来源方式
     * @return
     */
//    private int getGoodsSource() {
//        Properties prop = PropertyUtil.readPropertyFile(DATA_SOURCE);
//        return Integer.parseInt(prop.getProperty(GoodsSource));
//    }
//
//    private int getQCSource() {
//        Properties prop = PropertyUtil.readPropertyFile(DATA_SOURCE);
//        return Integer.parseInt(prop.getProperty(QCSource));
//    }
}
